<%-- 
    Document   : editInfo
    Created on : Nov 18, 2013, 12:45:07 PM
    Author     : BAOLA
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<jsp:include page="header.jsp"/>
<jsp:include page="leftbar.jsp"/>
<script type="text/javascript">
    var regEmail = /^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;
    function validateForm(form) {
        var email = form.email.value;
        var error = [];
        if (!regEmail.test(email)) {
            error[error.length] = "Please enter a valid email";
        }
        if (error.length >0) {
            reportError(error);
            return false;
        }
        return true;
    }

    function reportError(error) {
        var error_container = document.getElementById("error-container");
        var error_ol = document.getElementById("error-ol");
        error_ol.innerHTML = "";
        for (i = 0; i < error.length; i++) {
            error_ol.innerHTML += '<li><label for="name" class="error">' +error[i]+ '</label></li>';
        }
        error_container.style.display = 'block';
        error_ol.style.display = 'block';
    }
</script>
<c:if test="${not empty sessionScope.USER}">
    <c:if test="${empty param.username} ">
        <jsp:forward page="error.jsp?error='Page does not exist'" />
    </c:if>
    <c:set var="username" value="${param.username}"/>
    <form action="editInfo.action" method="POST" onsubmit="return validateForm(this);">
        <div class="main-wrapper">
            <div class="container-fluid">
                <div class="row-fluid">
                    <div class="span12">
                        <div class="primary-head">
                            <h3 class="page-header">Edit User's Info</h3>
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span12">
                        <div class="profile-info">
                            <div id="error-container" class="error-container" style="display: none;">
                                <h4>Errors occur, please see below for detail</h4>
                                <ol id="error-ol" style="display: none;"></ol>
                            </div>
                            <c:import url="WEB-INF/xml/account.xml" var="xml" charEncoding="UTF-8"/>
                            <c:import url="WEB-INF/xsl/editInfo.xsl" var="xsl" charEncoding="UTF-8"/>
                            <x:transform xml="${xml}" xslt="${xsl}">
                                <x:param name="username" value="${username}"/>
                            </x:transform>
                            <input type="submit" name="Save" value="Save" class="btn btn-extend"/>
                            <input type="reset" name="Cancel" value="Cancel" class="btn btn-extend"/>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</c:if>

<c:if test="${empty sessionScope.USER}">
    <jsp:forward page="login.jsp"/>
</c:if>
<jsp:include page="footer.jsp"/>
